{% extends 'wiki/base.html' %}

{% if revision %}
    {% set page_title = revision.title %}
{% else %}
    {% set page_title = page_name %}
{% endif %}

{% block title %}{{ page_title }} - {{ sitename }}{% endblock %}

{%- block extrahead -%}
    {{- super() -}}
    {% if revision -%}
        <link type="application/atom+xml" rel="alternate" href="{{ url_for('wiki/changes-atom', page_path=page_path) }}" title="{{ _('Atom feed for changes in this page') }}">
    {%- endif %}
{% endblock %}

{% block content %}
    <h1>
        {%- if revision -%}<span id="bookmark-widget"><input type="checkbox" name="sel" value="1"><label id="lab" for="sel">{{ _('Bookmark this') }}</label></span>{%- endif -%}
        {{ page_title }}
        {% if revision %}
            <span id="{{ slug }}"></span>
            <a class="headerlink" href="#{{ slug }}" title="{{ _('Permalink to this headline') }}">&para;</a>
        {% endif %}
    </h1>

    {% if revision %}
        {% if version %}
            <p class="warning">
                {{ _('This is an older version of this page. See the most updated version <a href="%(url)s">here</a>.', url=url_for('wiki/index', page_path=page_path)) }}
            </p>
        {% endif %}
        {{ revision.body|safe }}
    {% else %}
        <p>
            {% trans url=url_for('wiki/edit', page_path=page_path) %}
            This wiki page doesn't exist yet. <a href="{{ url }}">Create this page</a>.
            {% endtrans %}
        </p>
    {% endif %}

    <ul class="wiki-page-info">
        {% if revision %}
            <li class="first">
            {% if revision.version == 'latest' %}
                {{ _('Latest version') }}</li>
            {% else %}
                {{ _('Version: %(version)s', version=revision.version) }}</li>
            {% endif %}
            <li>
                {% trans user_url=url_for('users/profile', username=revision.editor.username), author=revision.editor.username, date=format_datetime(revision.created, 'short'), date_iso=format_datetime(revision.created, 'iso') %}
                    Edited by <a href="{{ user_url }}">{{ author }}</a> on <time pubdate="pubdate" datetime="{{ date_iso }}">{{ date }}</time>
                {% endtrans %}
            </li>
            <li><a href="{{ url_for('wiki/changes', page_path=page_path) }}" title="{{ _('Change history for this page') }}">{{ _('History') }}</a></li>
            <li>{{ _('Tags') }} {% for tag in revision.tags %}<a href="{{ url_for('wiki/tag', tags=tag) }}">{{ tag }}</a> {% endfor %}</li>
        {% else %}
            <li class="first">{{ _('This page is not versioned yet.') }}</li>
        {% endif %}
        <li class="last"><a href="{{ url_for('wiki/edit', page_path=page_path, version=version) }}" title="{{ _('Edit this page') }}">{{ _('Edit') }}</a></li>
    </ul>
{% endblock %}

{% block extrabody %}
    {{ super() }}
    {#<script>
    $(document).ready(function() {
        $.tipfy.wiki.set_edit_section('{{ url_for('wiki/edit', page_path=page_path, version=version) }}', '{{ _('edit') }}', '{{ _('Edit this section') }}');
    });
    </script>#}
    <script>
        {% if revision %}
        moe.setBookmarkableItem('bookmark-widget', '{{ url_for("users/set-favorite") }}', '{{ revision.key() }}');
        {% endif %}
    </script>
{% endblock %}
